import React from 'react';
/**
 * Created by 林洪东 on 2020/6/13.
 */
export class Clock extends React.Component {
    constructor(props) {
        super(props);
        this.state = {date: new Date()}
    }

    componentDidMount() {
        this.createTime = setInterval(() => {
            this.tick()
        }, 1000)
    }

    componentWillUnmount() {
        clearInterval(this.createTime);
    }

    tick() {
        this.setState({date: new Date()});
        // console.log('===>>>', this.state.date);
    }

    render() {
        return (
            <div>
                {/*<h1>Hello, world!</h1>*/}
                {/*<h2>It is {this.state.date.toLocaleTimeString()}.</h2>*/}
                <h2>当前时间：{this.state.date + ''}</h2>
            </div>
        );
    }
}